﻿package mortal.game.net.command.guild
{
    import Framework.MQ.*;
    import Message.Command.*;
    import Message.Game.*;
    import Message.Public.*;
    import com.gengine.debug.*;
    import extend.language.*;
    import mortal.game.cache.*;
    import mortal.game.manager.*;
    import mortal.game.manager.msgTip.*;
    import mortal.game.mvc.*;
    import mortal.game.net.broadCast.*;
    import mortal.game.scene3D.layer3D.utils.*;
    import mortal.game.view.systemSetting.*;
    import mortal.mvc.core.*;

    public class GuildCommand extends BroadCastCall
    {

        public function GuildCommand(param1:Object)
        {
            super(param1);
            return;
        }// end function

        override public function call(param1:MessageBlock) : void
        {
            var _loc_2:SPlayerInviteInfo = null;
            var _loc_3:SGuildLeaderImpeach = null;
            var _loc_4:int = 0;
            var _loc_5:SGuildMember = null;
            var _loc_6:SGuildInfo = null;
            var _loc_7:SPlayerGuildInfo = null;
            var _loc_8:Boolean = false;
            var _loc_9:Boolean = false;
            var _loc_10:SGuildMember = null;
            var _loc_11:SMiniPlayer = null;
            var _loc_12:SMiniPlayer = null;
            var _loc_13:SJoinGuildInfo = null;
            var _loc_14:SGuildPositonModify = null;
            var _loc_15:SGuildApplyNum = null;
            var _loc_16:SGuildWarehouseUpdate = null;
            var _loc_17:SGuildApplyCondition = null;
            var _loc_18:SGuildActivity = null;
            var _loc_19:SGuildGardenInfo = null;
            switch(param1.messageHead.command)
            {
                case EPublicCommand._ECmdPublicGuildInvite:
                {
                    _loc_2 = param1.messageBase as SPlayerInviteInfo;
                    if (_loc_2.guild.guildId > 0)
                    {
                        if (SystemSetting.instance.isRefuseBeAddToGuild.bValue)
                        {
                            GameProxy.guild.dealInvite(_loc_2.inviter.entityId.id, _loc_2.guild.guildId, false, EInviteMode._EInviteForJoinGuild);
                            return;
                        }
                        Cache.instance.guild.cacheInviteInfo(_loc_2);
                        NetDispatcher.dispatchCmd(ServerCommand.GUILD_INVITE, _loc_2.inviter);
                    }
                    else
                    {
                        NetDispatcher.dispatchCmd(ServerCommand.GuildInviteCreate, _loc_2.inviter);
                    }
                    break;
                }
                case EPublicCommand._ECmdPublicGuildImpeach:
                {
                    _loc_3 = param1.messageBase as SGuildLeaderImpeach;
                    NetDispatcher.dispatchCmd(ServerCommand.GUILD_IMPEACH, _loc_3);
                    break;
                }
                case EPublicCommand._ECmdPublicGuildLeaderImpeachEnd:
                {
                    NetDispatcher.dispatchCmd(ServerCommand.GUILD_IMPEACH_END, null);
                    break;
                }
                case EPublicCommand._ECmdPublicGuildApplyNum:
                {
                    _loc_4 = (param1.messageBase as SGuildApplyNum).num;
                    Cache.instance.guild.selfGuildInfo.applyNum = _loc_4;
                    NetDispatcher.dispatchCmd(ServerCommand.GUILD_INFO_UPDATE, null);
                    break;
                }
                case EPublicCommand._ECmdPublicGuildNewMember:
                {
                    _loc_5 = param1.messageBase as SGuildMember;
                    Cache.instance.guild.selfGuildInfo.addMember(_loc_5);
                    NetDispatcher.dispatchCmd(ServerCommand.GUILD_NEW_MEMBER_ADD, null);
                    break;
                }
                case EPublicCommand._ECmdPublicGuildAttributeUpdate:
                {
                    _loc_6 = param1.messageBase as SGuildInfo;
                    Cache.instance.guild.selfGuildInfo.syncBaseInfo(_loc_6);
                    NetDispatcher.dispatchCmd(ServerCommand.GUILD_INFO_UPDATE, null);
                    break;
                }
                case EPublicCommand._ECmdPublicPlayerGuildInfoUpdate:
                {
                    _loc_7 = param1.messageBase as SPlayerGuildInfo;
                    this.showContributionRecordOnChat(_loc_7, Cache.instance.guild.selfGuildInfo.selfInfo);
                    if (Cache.instance.guild.selfGuildInfo.selfInfo && _loc_7.contribution != Cache.instance.guild.selfGuildInfo.selfInfo.contribution)
                    {
                        _loc_8 = true;
                        _loc_9 = _loc_7.contribution > Cache.instance.guild.selfGuildInfo.selfInfo.contribution;
                    }
                    Cache.instance.guild.selfGuildInfo.syncSelfInfo(_loc_7);
                    Cache.instance.guild.selfGuildInfo.setGuildID(_loc_7.guildId);
                    Cache.instance.role.roleEntityInfo.updateGuildId(_loc_7.guildId);
                    Cache.instance.role.roleEntityInfo.updateGuildName(_loc_7.guildName);
                    Cache.instance.role.roleEntityInfo.updateGuildPosition(_loc_7.position);
                    ThingUtil.isNameChange = true;
                    NetDispatcher.dispatchCmd(ServerCommand.GUILD_INFO_UPDATE, null);
                    if (_loc_8)
                    {
                        NetDispatcher.dispatchCmd(ServerCommand.GuildResourceAdd, _loc_9);
                    }
                    break;
                }
                case EPublicCommand._ECmdPublicGuildMemberInfoUpdate:
                {
                    _loc_10 = param1.messageBase as SGuildMember;
                    Cache.instance.guild.selfGuildInfo.updateMember(_loc_10);
                    NetDispatcher.dispatchCmd(ServerCommand.GUILD_INFO_UPDATE, null);
                    break;
                }
                case EPublicCommand._ECmdPublicGuildKickOut:
                {
                    _loc_11 = param1.messageBase as SMiniPlayer;
                    if (_loc_11.entityId.id == Cache.instance.role.entityInfo.entityId.id)
                    {
                        Cache.instance.guild.selfGuildInfo.exitGuild();
                        MsgManager.showRollTipsMsg(Language.getString(20507));
                        NetDispatcher.dispatchCmd(ServerCommand.GUILD_EXIT, null);
                    }
                    else
                    {
                        Cache.instance.guild.selfGuildInfo.removeMember(_loc_11.entityId.id);
                        NetDispatcher.dispatchCmd(ServerCommand.GUILD_INFO_UPDATE, null);
                    }
                    break;
                }
                case EPublicCommand._ECmdPublicPlayerExitGuild:
                {
                    _loc_12 = param1.messageBase as SMiniPlayer;
                    if (Cache.instance.guild.selfGuildInfo == null)
                    {
                        return;
                    }
                    if (_loc_12.entityId.id == Cache.instance.role.entityInfo.entityId.id)
                    {
                        NetDispatcher.dispatchCmd(ServerCommand.GUILD_EXIT, null);
                    }
                    Cache.instance.guild.selfGuildInfo.removeMember(_loc_12.entityId.id);
                    NetDispatcher.dispatchCmd(ServerCommand.GUILD_INFO_UPDATE, null);
                    break;
                }
                case EPublicCommand._ECmdPublicJoinGuildResult:
                {
                    _loc_13 = param1.messageBase as SJoinGuildInfo;
                    NetDispatcher.dispatchCmd(ServerCommand.GUILD_SELF_JION_SUCCESS, _loc_13);
                    break;
                }
                case EPublicCommand._ECmdPublicDisbandGuild:
                {
                    NetDispatcher.dispatchCmd(ServerCommand.GUILD_DISBAND, null);
                    NetDispatcher.dispatchCmd(ServerCommand.GUILD_EXIT, null);
                    break;
                }
                case EPublicCommand._ECmdPublicWarningMemberNum:
                {
                    _loc_4 = (param1.messageBase as SGuildApplyNum).num;
                    Log.debug("公会警告成员数:" + _loc_4);
                    Cache.instance.guild.selfGuildInfo.warnMemberNum = _loc_4;
                    NetDispatcher.dispatchCmd(ServerCommand.GUILD_INFO_UPDATE, null);
                    break;
                }
                case EPublicCommand._ECmdPublicCreateBranchGuild:
                {
                    break;
                }
                case EPublicCommand._ECmdPublicGuildPositionModify:
                {
                    _loc_14 = param1.messageBase as SGuildPositonModify;
                    Cache.instance.guild.selfGuildInfo.positionModifyVec.push(_loc_14);
                    NetDispatcher.dispatchCmd(ServerCommand.GuildPositionModify, null);
                    break;
                }
                case EPublicCommand._ECmdPublicGuildWarehouseApplyNum:
                {
                    _loc_15 = param1.messageBase as SGuildApplyNum;
                    Cache.instance.guild.selfGuildInfo.wareHouse.allApplyNum = _loc_15.num;
                    NetDispatcher.dispatchCmd(ServerCommand.GuildWareHouseAllApplyNumUpdate, null);
                    break;
                }
                case EPublicCommand._ECmdPublicGuildWarehouseUpdate:
                {
                    _loc_16 = param1.messageBase as SGuildWarehouseUpdate;
                    Cache.instance.guild.selfGuildInfo.wareHouse.writeWarehouseItems(_loc_16.items);
                    Cache.instance.guild.selfGuildInfo.wareHouse.writeWarehouseMoneys(_loc_16.moneyMap);
                    NetDispatcher.dispatchCmd(ServerCommand.GuildWareHouseDataUpdate, null);
                    break;
                }
                case EPublicCommand._ECmdPublicGuildApplyCondition:
                {
                    _loc_17 = param1.messageBase as SGuildApplyCondition;
                    Cache.instance.guild.selfGuildInfo.applyCondition = _loc_17;
                    NetDispatcher.dispatchCmd(ServerCommand.GuildApplyConditionUpdate, null);
                    break;
                }
                case EGateCommand._ECmdGateTaskGuildCreated:
                {
                    NetDispatcher.dispatchCmd(ServerCommand.GUILD_CREATE, null);
                    break;
                }
                case EPublicCommand._ECmdPublicGuildActivity:
                {
                    _loc_18 = param1.messageBase as SGuildActivity;
                    Cache.instance.guild.selfGuildInfo.baseInfo.activity = _loc_18.activity;
                    NetDispatcher.dispatchCmd(ServerCommand.GUILD_INFO_UPDATE, null);
                    break;
                }
                case EPublicCommand._ECmdPublicGuildGarden:
                {
                    _loc_19 = param1.messageBase as SGuildGardenInfo;
                    Cache.instance.guild.selfGuildInfo.gardenInfo = _loc_19;
                    NetDispatcher.dispatchCmd(ServerCommand.GuildSelfGardenUpdate, null);
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        private function showContributionRecordOnChat(param1:SPlayerGuildInfo, param2:SPlayerGuildInfo) : void
        {
            var _loc_3:int = 0;
            var _loc_4:MsgTypeImpl = null;
            var _loc_5:String = null;
            if (param2 != null)
            {
                _loc_3 = param1.contribution - param2.contribution;
                if (_loc_3 == 0)
                {
                    return;
                }
                if (_loc_3 > 0)
                {
                    _loc_4 = MsgHistoryType.GetMsg;
                }
                else if (_loc_3 < 0)
                {
                    _loc_4 = MsgHistoryType.LostMsg;
                }
                _loc_5 = Language.getStringByParam(20508, _loc_4.name + Math.abs(_loc_3).toString());
                MsgManager.addTipText(_loc_5, _loc_4);
            }
            return;
        }// end function

    }
}
